package com.itheima.service.imp;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.common.DTO.CheckItemDTO;
import com.itheima.common.entity.PageResult;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.mapper.CheckgroupCheckitemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CheckItemServiceImp implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;
    @Autowired
    private CheckgroupCheckitemMapper checkgroupCheckitemMapper;


    /**
     * 新增检查项
     *
     * @param checkItem
     * @return
     */
    public int add(CheckItem checkItem) {

        return checkItemMapper.add(checkItem);
    }

    /**
     * 删除检查项
     */
    public int delete(Integer id) {
        return checkItemMapper.delete(id);
    }

    /**
     * 根据id查询检查项
     */
    public CheckItem findById(Integer id) {
        return checkItemMapper.findById(id);
    }

    /**
     * 编辑检查项
     */
    public int edit(CheckItem checkItem) {
        return checkItemMapper.edit(checkItem);
    }


    /**
     * 分页查询
     */
    public PageResult pageQuery(CheckItemDTO checkItemDTO) {
        PageHelper.startPage(checkItemDTO.getCurrentPage(), checkItemDTO.getPageSize());
        Page<CheckItem> page = checkItemMapper.pageQuery(checkItemDTO.getQueryString());
        return new PageResult(page.getTotal(), page.getResult());
    }

    /**
     * 根据检查组id查询检查项id
     * @param checkGroupId
     * @return
     */
    public List<Integer> findCheckItemIdsByCheckGroupId(Integer checkGroupId) {
        return checkgroupCheckitemMapper.findCheckItemIdsByCheckGroupId(checkGroupId);
    }

    /**
     * 查询所有检查项
     * @return
     */
    public List<CheckItem> findAll() {
        return checkItemMapper.findAll();
    }
}
